package com.bolt.support.captcha.autoconfigure;


import com.bolt.support.captcha.CaptchaProperties;
import com.bolt.support.captcha.CaptchaService;
import com.bolt.support.captcha.impl.CaptchaServiceFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(CaptchaProperties.class)
@ConditionalOnProperty(name = "bolt.captcha.enabled",havingValue = "true")
public class CaptchaAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public CaptchaService captchaService(CaptchaProperties properties) {
        return CaptchaServiceFactory.getCaptchaService(properties);
    }
}